# encoding = utf-8

from application.logging import logger
from application.model.v3_model.CV_Parameter_online.get_best_params_ import get_best_params_
from application.utils.CodeTimingUtil import CodeTimingUtil


@CodeTimingUtil(name="[调参]CV_weight")
def CV_weight(train_x, train_y, n_estimators):
    #
    cv_params = {
        "max_depth": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
        "min_child_weight": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
    }
    #
    other_params = {
        "learning_rate": 0.05,
        "n_estimators": n_estimators,
        "max_depth": 9,
        "min_child_weight": 15,
        "seed": 0,
        "subsample": 1,
        "colsample_bytree": 0.6,
        "gamma": 0,
        "reg_alpha": 0.03,
        "reg_lambda": 0.03
    }
    #
    logger.info(f"调参开始[max_depth,min_child_weight]: {'*' * 50}")
    best_params_ = get_best_params_(train_x=train_x, train_y=train_y, cv_params=cv_params, other_params=other_params)
    max_depth = best_params_["max_depth"]
    min_child_weight = best_params_["min_child_weight"]
    logger.info(f"调参结束[max_depth,min_child_weight]: [{max_depth}, {min_child_weight}] {'*' * 50}")
    return max_depth, min_child_weight

    pass


pass
if __name__ == "__main__":
    pass
